//
// Created by Akashic on 2024/7/10.
//

#include "number.h"

uint16_t *toUint16(uint16_t value) {
	uint16_t *tmp = (uint16_t *) malloc(sizeof(uint16_t));
    tmp[0] = value;
    return tmp;
}

uint8_t *toUint8(uint8_t value) {
	uint8_t *tmp = (uint8_t *) malloc(sizeof(uint8_t));
    tmp[0] = value;
    return tmp;
}

uint32_t *toUint32(uint32_t value) {
	uint32_t *tmp = (uint32_t *) malloc(sizeof(uint32_t));
    tmp[0] = value;
    return tmp;
}

uint64_t *toUint64(uint64_t value) {
	uint64_t *tmp = (uint64_t *) malloc(sizeof(uint64_t));
    tmp[0] = value;
    return tmp;
}


void freeUint16(void *value) {
    if (value != NULL) {
    	uint16_t *tmp = (uint16_t *) value;
        free(tmp);
    }
}

void freeUint8(void *value) {
    if (value != NULL) {
    	uint8_t *tmp = (uint8_t *) value;
        free(tmp);
    }
}

void freeUint32(void *value) {
    if (value != NULL) {
    	uint32_t *tmp = (uint32_t *) value;
        free(tmp);
    }
}

void freeUint64(void *value) {
    if (value != NULL) {
    	uint64_t *tmp = (uint64_t *) value;
        free(tmp);
    }
}



void printHex(Bytes *bytes){
	for (int i=0; i<bytes->len; i++){
		printf("%02x", bytes->data[i]);
	    fflush(stdout);
	}
	printf("\n");
	fflush(stdout);
}


void freeBytes(void *value){
	if(value != NULL){
		Bytes *bytes = (Bytes*)value;

		if(bytes->data != NULL){
			free(bytes->data);
		}
		free(bytes);
	}
}
